//
//  BeeGroupTopicCell.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/7.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "BeeGroupTopicCell.h"
#import "BeePhotoImageView.h"
#import "UrlLabel.h"
#import "TopicObj.h"
#import "FbeeImageButton.h"

@interface BeeGroupTopicCell()
{
    //头像
    BeePhotoImageView *photo;
    //昵称
    UILabel *nickName;
    //置顶
    UIImageView *topFlag;
    //内容
    UrlLabel *content;
    //展开
    UIButton *allBtn;
    //日期
    UILabel *dateInfo;
    //分享
    FbeeImageButton *shareBtn;
    //评论
    FbeeImageButton *commentBtn;
    
}


@end

@implementation BeeGroupTopicCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = FBEE_COLOR_BACKGROUND;
        [self buildView];
    }
    
    return self;
}

-(void)buildView
{
    //背景
//    CALayer *bg = [[CALayer alloc]init];
//    bg.frame = CGRectMake(0, 0, IPHONEWIDTH, 11);
//    bg.backgroundColor = FBEE_COLOR_AS_BACKGROUND.CGColor;
//    [self.layer addSublayer:bg];
    
    photo = [[BeePhotoImageView alloc] initWithFrame:CGRectMake(15, 30, 35, 35) imgByTitle:@"" photoStyle:BeePhotoCellStyle];
    [self addSubview:photo];
    
    nickName = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addBackGoundColor(FBEE_COLOR_PLACEHOLDER);
        make.addTextColor(FBEE_COLOR_THEME).addFont([UIFont systemFontOfSize:18.0f]);
        make.setFrame(CGRectMake(0, 0, 100, 23));
        make.left = photo.right + 10;
        make.top = photo.top - 1;
        [self addSubview:make];
    }];
    
    topFlag = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 25, 15)];
    topFlag.image = [UIImage imageNamed:@"beegroup_top"];
    topFlag.hidden = YES;
    [self addSubview:topFlag];
    
    allBtn = [UIButton makeButton:^(TTButtonExtend *make) {
        make.addFont([UIFont systemFontOfSize:14.0f]).addTitle(@"全文").addTitleColor(FBEE_COLOR_BLUE,UIControlStateNormal);
        make.setFrame(CGRectMake(0, 0, 30, 30));
        make.hidden = YES;
    }];
    allBtn.userInteractionEnabled = NO;
    [self addSubview:allBtn];
    
    dateInfo = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addBackGoundColor(FBEE_COLOR_PLACEHOLDER);
        make.addTextColor(FBEE_COLOR_INFO).addFont([UIFont systemFontOfSize:12]);
        make.setFrame(CGRectMake(0, 0, 100, 13));
        make.left = nickName.left;
        make.top = content.bottom + 27;
        [self addSubview:make];
    }];
    
    commentBtn = [[FbeeImageButton alloc] initWithFrame:CGRectMake(IPHONEWIDTH - 70, content.bottom + 20, 70, 20) imageName:@"beegroup_comment"];
    
    @weakify(self)
    commentBtn.onClick = ^{
        @strongify(self)
        
        if (!self.dataObj.isJoin) {
            [[NSNotificationCenter defaultCenter] postNotificationName:Notification_JoinBeeGroup object:self.dataObj.groupId];
            return ;
        }
        
        [[JumpManager sharedManager] jumpToTopicDetail:self.dataObj];
        
    };
    [self addSubview:commentBtn];
    
    shareBtn = [[FbeeImageButton alloc] initWithFrame:CGRectMake(commentBtn.left - 70, content.bottom + 20, 70, 20) imageName:@"beegroup_share"];
    
    shareBtn.onClick = ^{
        [[NSNotificationCenter defaultCenter] postNotificationName:Notification_Share object:nil];
    };
    [self addSubview:shareBtn];
    
    
    
}

-(void)setDataObj:(TopicObj *)obj
{
    [photo setTitle:obj.nickname];
    
    nickName.backgroundColor = [UIColor clearColor];
    nickName.text = obj.nickname;
    [nickName sizeToFit];
    nickName.height = 23;
    
    topFlag.hidden = !obj.isTop;
    topFlag.left = nickName.right + 5;
    topFlag.top = photo.top + 1;
    
    if (content) {
        [content removeFromSuperview];
    }
    content = obj.contentLab;
    content.left = photo.right + 10;
    content.top = nickName.bottom + 6;
    [self addSubview:content];
    
    content.width = IPHONEWIDTH - 60 - 20;
    content.height = obj.contentH;
    
    allBtn.hidden = !obj.isShowAll;
    allBtn.top = content.bottom;
    allBtn.left = content.left;

    dateInfo.bottom = obj.height - 15;
    dateInfo.backgroundColor = [UIColor clearColor];
    dateInfo.text = obj.createTime;
    
    [commentBtn setTtile:obj.commentNum];
//    [commentBtn btnSizeToFit];
    commentBtn.bottom = obj.height - 15;
    
    [shareBtn setTtile:obj.shareNum];
//    [shareBtn btnSizeToFit];
    shareBtn.bottom = obj.height - 15;
    
    _dataObj = obj;
}

@end
